unit Con_HistMaq;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids;

type
  TFrmCon_HistMaq = class(TFrmConsulta)
    Label1: TLabel;
    ed_descricao: TEdit;
    dbgrid: TDBGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
    procedure ed_descricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    procedure faz_consulta;
  public
    { Public declarations }
  end;

var
  FrmCon_HistMaq: TFrmCon_HistMaq;
  hm_codhist    : string;

implementation

uses dm,clsHist_Maquina,db,dbtables;

var hist_maquina: THist_Maquina;
    tq          : TQuery;
    tds         : TDataSource;

{$R *.DFM}

procedure TFrmCon_HistMaq.FormCreate(Sender: TObject);
begin
  inherited;
 hist_maquina:= THist_Maquina.Create;
 tq          := TQuery.Create(self);
 tds         := TDataSource.Create(self);
end;

procedure TFrmCon_HistMaq.FormDestroy(Sender: TObject);
begin
  inherited;
 hist_maquina.free;
 tq.free;
 tds.free;
end;

procedure TFrmCon_HistMaq.FormActivate(Sender: TObject);
begin
  inherited;
 tq.databasename  := dmint.db.databasename;
 tds.DataSet      := tq;
 dbgrid.DataSource:= tds;
 faz_consulta;
end;

procedure TFrmCon_HistMaq.faz_consulta;
begin
 if ed_descricao.text='' then ed_descricao.text:= ' ';
 hist_maquina.Consultar(ed_descricao.text,tq);
 dbgrid.refresh;
end;

procedure TFrmCon_HistMaq.BtnFecharClick(Sender: TObject);
begin
 hm_codhist:= tq.fieldbyname('Cod_HistMaq').asstring;
 inherited;
end;

procedure TFrmCon_HistMaq.ed_descricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
 if key=12 then faz_consulta;
end;

end.
